package com.gthncz;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.gthncz.beans.HelloWorld;

public class ScopeDemo {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext("Beans_scope.xml");
		
		/**
		 * test singleton scope
		 */
		HelloWorld singletonBean1 = (HelloWorld) context.getBean("singletonBean");
		HelloWorld singletonBean2 = (HelloWorld) context.getBean("singletonBean");
		// 比较两个对象的地址
		System.out.println("Singleton Bean is equal ?  " + (singletonBean1 == singletonBean2));
		
		/**
		 * test prototype scope
		 */
		HelloWorld prototypeBean1 = (HelloWorld) context.getBean("prototypeBean");
		HelloWorld prototypeBean2 = (HelloWorld) context.getBean("prototypeBean");
		System.out.println("Prototype Bean is equal ?  " + (prototypeBean1 == prototypeBean2));
		
		// more information about bean scope
	}

}
